<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>确认订单_{$webname}</title>
<meta name='keywords'    content='{$keywords}'>
<meta name='description' content='{$description}'>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css" />
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css" />
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css" />
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome-ie7.min.css" />
<![endif]-->
<!--公共样式结束-->
<!--页面样式开始-->
<link href="__PUBLIC__/Plugins/Validform/css/validform.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/page_confirm.css" />

<!--页面样式结束-->
<script type="text/javascript" src="{$NOW_THEME_URL}/Assets/Js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="{$NOW_THEME_URL}/Assets/Js/jquery.SuperSlide.2.1.1.js"></script>
<script src="__PUBLIC__/Plugins/Datepicker/WdatePicker.js"></script>
<style>
.invoice_title{
	border:1px solid #CCCCCC;
	height:20px;
	width:180px;
}
.dishestime{
	background:#FF6666;
	color:#FFF;
	padding:3px 10px;
}
</style>
</head>

<body>
<div class="zhezhao"></div>
<div class="mask"></div>
	<div class="zz">
	<!--top start-->
	<include file="Public:header" lang="true" />
	<!--top end-->
	<!--content start-->
	<div class="content">
		<div class="buzou clearfix">
			<div class="buzou_left clearfix">
				<dl>
					<dt>1.选择地址</dt>
					<dd><a href="{:U('Index/address')}"></a></dd>
				</dl>
				<dl>
					<dt>2.选择餐厅</dt>
					<dd><a href="{:U('Restaurant/index')}"></a></dd>
				</dl>
				<dl>
					<dt>3.选择菜品</dt>
					<dd><a href="{:U('Dishes/index')}&id={$outlet.id}"></a></dd>
				</dl>
				<dl class="hover">
					<dt>4.确认订单</dt>
					<dd><a href="#"></a></dd>
				</dl>
				<dl>
					<dt>5.下单成功</dt>
					<dd></dd>
				</dl>
			</div>
			<div class="buzou_right">
				<a href="http://vipwebchat.tq.cn/pageinfo.jsp?version=vip&admiuin=9632675&ltype=100&iscallback=0&page_templete_id=79615&is_message_sms=0&is_send_mail=0&action=acd&acd=1&type_code=1" target=_blank><img src="http://float2006.tq.cn/staticimg.jsp?version=vip&admiuin=9632675&ltype=100&action=acd&acd=1&type_code=1&onlinepic=http://userfiles.tq.cn/userfiles/upload_163/9632675/1411565972.png&offlinepic=http://userfiles.tq.cn/userfiles/upload_163/9632675/1411628431.png" border='0' /></a>
			</div>
		</div>
		<eq name="status" value="1">
			<div class="com_tips">温馨提示: 您已经是老会员, 如果没有疑问的话, 请直接下单!</div>
		<else />
			<div class="com_tips">温馨提示: 请拨打<em class="com_tips tels">{$telphone}</em>，确认您的订单!</div>
		</eq>
		
		<div class="confirm clearfix">
		<form action="{:U('Order/confirm')}" method="post" class="formTable addressForm" >
		<input type="hidden" name="is_exempt" value="{$outlet.is_exempt}" />
		<input type="hidden" name="outid" id="outid" value="{$outlet.id}" />
			<h1 class="color_main">确认订单<em>(请检查您的订单)</em></h1>
			<div class="address_window">
            <input type="hidden" name="addressid"  value="{$query.addid}">
            <input type="hidden" name="longitude"  value="{$query.pointlng}">
            <input type="hidden" name="latitude"   value="{$query.pointlat}">
            <input type="hidden" name="city"       value="{$query.cityid}">
            <input type="hidden" name='memaddress' value='{$memaddress.id}'>
            
            <php>if($memaddress['id']){</php>
            <div class="outside" flag="1">
                <span class="outside_tit"><b>配送到：</b> </span>
                <span><i class="icon-caret-right"></i>&nbsp;【{$memaddress.realname}&nbsp;{$memaddress.mobile}】{$query['adds']}</span>
            </div>
            <php>}</php>
            
            <table id="add_form" border="0" cellpadding="0" cellspacing="0" class="add_position" <notempty name='memaddress.id'>style='display:none'</notempty>>                
                <tr class="yanz">
                	<th>&nbsp;</th>
                    <td><div class="" id="Validform_errortip_div"></div></td>
                </tr>
                <tr>
                    <th>收货人：</th>
                    <td>
                        <input type="text" id="realname" name="realname" placeholder="请输入收货人姓名" datatype="*"
                        nullmsg="请输入收货人姓名" errormsg="请输入收货人姓名" value="{$memaddress.realname}">
                    </td>
                </tr>
                <empty name="memaddress.id">
	                <tr>
	                    <th>密码：</th>
	                    <td>
	                        <input type="password" id="password" name="password" placeholder="请输入密码" datatype="*6-18" 
	                        nullmsg="请输入您的密码" errormsg="您的密码不能少于六位数">（作为您注册kkrabbit会员的密码）
	                    </td>
	                </tr>
                <tr>
                    <th>邮箱：</th>
                    <td>
                        <input type="text" id="email" name="email" placeholder="请输入邮箱地址" datatype="e" 
                        nullmsg="请输入您的邮箱地址" errormsg="邮箱输入格式不正确">（例：xyz@163.com，作为您登录kkrabbit的账号）
                    </td>
                </tr>
                </empty>
                <tr>
                    <th>联系电话：</th>
                    <td>
                        <input type="text" id="mobile" name="mobile" placeholder="请输入联系电话" datatype="*11-12" 
                        nullmsg="请输入您的联系电话" errormsg="联系电话输入格式不正确" value="{$memaddress.mobile}">（例：18588889999或01066668888，填写正确的电话方便快递与您联系）
                    </td>
                </tr>
                <tr>
                    <th>常用地址：</th>
                    <td>
                    	<empty name="memaddress.id">
                    		<input type="text" id="adds" name="ads" readonly value="{$query.adds}">
                    	<else />
                    		<input type="text" id="adds" name="ads" readonly value="{$memaddress.ads}">
                    	</empty>
                    </td>
                </tr>
                <tr>
                    <th>详细地址：</th>
                    <td>
                    	<input type="text" id="detail" name="detail" placeholder="请补充您的详细地址" datatype="*" 
                        nullmsg="请补充您的详细地址" errormsg="请补充您的详细地址" value="{$memaddress.detail}">（补充正确的详细地址快递才能高效的送达）
                    </td>
                </tr>			
            </table>
            </div>
            <div class="confirm1"></div>
			<div class="confirm2">
				<!--<h2 class="color_main">Restaurant of your choice：Avocado Tree</h2>-->
					<table width="100%" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<th class="name">食品</th>
							<th>属性</th>
							<th>单价</th>
							<th>数量</th>
							<th>小计</th>
							<th>操作</th>
						</tr>
						<tbody id="cartlist">
							<volist name="cart.list" id="k" key="vo" >
								<tr>
									<td align="left" class="name">
										{$k.title}
										<p><input type="text" placeholder="您可以对每道菜品进行备注" cartid="{$k.id}"  class="nameinput asks"/></p>
										<div class="cnote-bubble group" id="n_p">
											<volist name="taste" id="vo" key="v" >
												<a class="cnote-item c_n_i" id="ask" cartid="{$k.id}">{$vo.zh-cn}</a>
											</volist>
										</div>
									</td>
									<td align="center">
										<notempty name="k.attr">
											<volist name="k.attr" id="m">
												<span class="entitle">{$m.title}：</span>
												<volist name="m.config" id="n">
													<span>
														{$n.title}
														<notempty name='n.num'>（{$n.num}份）</notempty>
													</span>　
												</volist>
												<br/>
											</volist>
										</notempty>
									</td>
									<td align="center" id="dprice">￥{$k.price}</td>
									<td align="center" id="td">
										<div class="number">
											<ul class="count">
												<li data-id="{$k.id}" price="{$k.price}" class="minus" >-</li>
												<li id="num{$k.id}" class="num">{$k.num}</li>
												<li data-id="{$k.id}" price="{$k.price}" class="plus">+</li>
												
											</ul>
										</div>
									</td>
									<td align="center" class="dprice">￥<span id="xjprice{$k.id}">{$k.xjprice}</span></td>
									<td align="center"><i class="icon-remove color_main remove" rel="{$k.id}"></i></td>
								</tr>
							</volist>
						</tbody>
						<tr>
							<td class="total" colspan="6" align="right">服务费：￥
								<span id="dliveryfee">{$dliveryfee|number_format=2}</span>
								<input type="hidden" id="shipfee" name="shipfee" value="{:session('dliveryfee')}">
							</td>
						</tr>
						<tr>
							<td class="total" colspan="6" align="right">
								总价：￥<span class="totalprice">{$totalprice|number_format=2}</span>
								<input type="hidden" name="foodfee" class="foodfee" value="{$totalprice-$dliveryfee}">
							</td>
						</tr>
						<tr>
							<td class="back" colspan="6" align="right">
								<span style="font-size:18px;">需要酒水饮料?</span>
								<a href="{:U('Dishes/index','id='.$outlet['id'])}">点击返回餐厅</a>
							</td>
						</tr>
					</table>
			</div>
			<div class="confirm3">
				<h2 class="color_main">订单备注</h2>
				<p><textarea name="content" cols="" rows="" placeholder="您可以在这里填写您对本次订单的特殊需求">{$member.remark}</textarea></p>
			</div>
			<div class="confirm4">
				<h2 class="color_main">配送时间</h2>
				<h3>
					<eq name="outlet.yuding" value="2">
						<p><input type="radio" name="time"  value="{$dliverytime}" id="now" checked/>马上&nbsp;&nbsp;&nbsp;&nbsp;
							大概 {$dliverytime+$cart['time']} 分钟
							<php>if($cart['time']>0){</php>
								<span class="dishestime">{$cart.title}需要{$cart.time}分钟</span>
							<php>}</php>	
							<input type="hidden" name="dishestime" value="{$cart.time}">
						</p>
					</eq>
					<p>
						<input type="radio" name="time"   value="-1" id="book" />预定
						<input type="text"  name="ydtime"  id="ydtime"  style="display:none;" onfocus="WdatePicker({minDate:'%y-%M-{%d}'})" class="Wdate">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="text"  name="sdltime" id="sdltime" style="display:none;" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm',minDate:'11:00',maxDate:'22:30'})" class="Wdate" />
					   -<input type="text"  name="edltime" id="edltime" style="display:none;" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm',minDate:'11:00',maxDate:'22:30'})" class="Wdate" />
						<input type="hidden" name="yuding" value="{$outlet.yuding}">
					</p>
				</h3>
			</div>
			<div class="confirm6">
				<eq name='outlet.is_tigong' value='1'>
					<span><input name="isinvoice" type="checkbox" value="1" />需要发票?
					<input type="text" name="invoice_title" id="invoice_title" class="invoice_title" placeholder="请输入发票抬头" style="display:none"></span>
				<else />
					<span><input name="isinvoice" type="checkbox" disabled/>该餐厅不提供发票</span>
				</eq>
				<!--<span><input name="isprint"   type="checkbox" value="1" />Need print?</span>-->
				<span><input name="isconfirm" id="isconfirm" type="checkbox" value="1"/>需要电话确认?</span>
			</div>
			<div id="freeDrink" class="confirm6" <php>if(($totalprice-$dliveryfee)<50)echo "style='display:none'"</php>>免费饮料：
				<eq name="isdrink" value="1">
					<volist name="sdrink" id="vo" >
						<span><input name="isdrink" type="radio" value="{$key}" <eq name="key" value="0">checked</eq>/>{$vo.zh-cn}</span>
					</volist>
				</eq>
			</div>
			<div class="confirm5">
				<i class=" icon-volume-down icon-2x"></i>
				因食材数量的有限性及市场价格的波动性，K.K.RABBIT可能没有及时更新菜牌和部分菜品的价格，您预订的菜品可能出现售罄、取消供应或价格不一致的状况，届时请以餐厅现行菜牌和价格为准。敬请谅解。
			</div>
			<div class="confirm5">
				<i class=" icon-volume-down icon-2x"></i>
				预定单如遇高峰期可能会出现半小时的延迟，准确送达时间我们难以告知，对此深表歉意。
			</div>
			<div class="order">
				<a href="{:U('Dishes/index','id='.$outlet['id'])}" class="fh">返回</a>
				<input type="submit" id="submit" value="提交" class="xd">
			</div>
			</form>
		</div>
	</div>
	<!--content end-->
	
	<!--footer start-->
	<include file="Public:footer" lang="true" />
	<!--footer end-->
		<a id="returnTop" href="javascript:scroll(0,0)">&nbsp;</a>
	</div>
	<div class="cityck selectcity">
		<h1>您还没有选择正确的地址，点击该按钮来选择地址</h1>
		<h3><a href="{:U('Index/index')}" class="ck">选择城市</a></h3>
	</div>
	<!--没有选择需要电话确认窗口开始-->
     <div class="telck istelck" style="display:none">
        <h1>是否需要电话确认？</h1>
        <h3><a id="sure_tel" class="sure_tel" style="cursor:pointer">需要</a><a class="ck goback" style="cursor:pointer">不需要</a></h3>
		<h2 style="color:#ba2f29">（如需取消订单，请在三分钟内致电：400-020-1717）</h2>
     </div>	
    <!--没有选择需要电话确认窗口结束-->
<script src="__PUBLIC__/Plugins/Validform/validform.min.js" ></script>
<script type="text/javascript">	
	$(function(){
		
		<notempty name="noneCity">
			$('.selectcity').show();
			$('.zhezhao').show();
		</notempty>
		
		var flag = true ;  //定义全局变量
		var msg  = "" ;    //定义全局变量
		$(".formTable").Validform({tiptype:function(msg,o,cssctl){
			var objtip=$("#Validform_errortip_div");cssctl(objtip,o.type);objtip.text(msg);}
			,tipmsg:{
					tit:"Prompt information",
					w:"Please input the correct information！",
					r:"信息验证通过！",
					c:"Checking information…",
					s:"Please fill in the information！",
					v:"The filled information has not been verified, please try later…",
					p:"Data are presented…",
					err:"Wrong! To address or return data format is wrong！",
					abort:"Ajax operation was canceled！"
			},
			beforeSubmit:function(data){
				if($('.istelck').is(':hidden')){
					if(!$("#isconfirm").prop("checked")){
						$('.zhezhao').show();
						$('.istelck').show();
						return false;
					}
				}
			}
		});

		//确定需要电话确认
		$("body").on('click','.sure_tel',function(){
			$("#isconfirm").prop('checked',true);
			$('#submit').click();
		});
		
		//不需要电话确认
		$(".goback").on('click',function(){
			$('#submit').click();
		});
		
		$(".zhezhao").on('click',function(){
			$(this).hide();
			$('.telck').hide();
		});
		
		//点击展开	 
		$('.outside').on('click',function(){
			var flag = $(".outside").attr("flag")	
			if(flag==1){				
				$('#add_form').show();	
				$('.outside').attr("flag",2)
				$('.outside i').removeClass("icon-caret-right")
				$('.outside i').addClass("icon-caret-down")
			}else{
				$('#add_form').hide();	
				$('.outside').attr("flag",1)
				$('.outside i').removeClass("icon-caret-down")
				$('.outside i').addClass("icon-caret-right")
			}
		});
		
		//返回顶部
		$(window).on('scroll',function(){
			var scrollTop = $(document).scrollTop();
		});

		
		//修改地址弹出窗口
		$('.addaddress span').on('click',function(){
			$('.mask').show();
			$('.address_window').show();
		});
		$('.address_window .return').on('click',function(){
			$('.mask').hide();
			$('.address_window').hide();	
		});
		$('.address_window').css('left',($(window).width()-660)/2+'px');
		$('.mask').height($(document.body).height());
		
		$('.saveaddress').live('click',function(){
			$('.mask').show();
			$('.address_window').show();
			var realname  = $("#realname").val();
			var mobile    = $("#mobile").val();
			var enaddress = $("#enaddress").val();
			var address   = "{$query.adds}"+enaddress;
			if(realname==""){
				$("#Validform_errortip_div").html("请填写收货人姓名");return false;
			}
			if(mobile==""){
				$("#Validform_errortip_div").html("请填写联系电话");return false;
			} 
			if(enaddress==""){
				$("#Validform_errortip_div").html("请补充详细地址");return false;
			}
			
			postData = $("#addressaddform").serialize();
			$.post("{:U('Public/add_address')}",postData,function(d){
				if(d.status==1){
					var id = "{$Think.get.id}";
					window.location.href="{:U('Order/confirm')}&id="+id;
				}else{
					alert('地址添加失败，请重试！');return false;
				}
			});
		});
		
		//发票
		$("input[name='isinvoice']").on('click',function(){
			if($(this).prop('checked')){
				$('.invoice_title').show();
			}else{
				$('.invoice_title').hide();
			}
		});
		
		//默认地址高亮显示
		$("input[name='addressid']").on('click',function(){
			if($(this).prop("checked")){
				var lng = $(this).parents('tr').attr('longitude');
				var lat = $(this).parents('tr').attr('latitude');
				getDliveryfee(lng,lat);
			}	
		});
		
		var yuding = "{$outlet.yuding}";
		if(yuding==1){
			$("#sdltime").show();
			$("#edltime").show();
			$("#ydtime").show();
			$("#ydtime").val("{:date('Y-m-d')}");
			$("input[name='time']").prop("checked",true);
		}
		
		//点击显示配送时间
		$("#book").on("click",function(){
			$("#sdltime").show();
			$("#edltime").show();
			$("#ydtime").show();
		});
		//点击隐藏配送时间
		$("#now").on("click",function(){
			$("#sdltime").hide();
			$("#edltime").hide();
			$("#ydtime").hide();
		});
		
		//地址删除
		$('.href').on('click',function(){
			var id = $(this).attr("rel"); 
			$.post("{:U('Member/address_index')}",{id:id});
		});
		
		//悬浮框显示隐藏
		$('.online').on('hover',function(){
			$('.online ul').toggle();
			//$('.rlico').toggleClass('rlico2');
		});
		
		//菜品口味
		$('.cnote-bubble a').on('click',function(){
			var neirong = $(this).html();
			var ask     = $(this).html();
			var cartid  = $(this).attr("cartid");
			var obj = $(this).parent().siblings().children('input');
			$(this).parent().siblings().children('input').val(neirong);
			askedit(ask,cartid);
		}); 
		//菜品口味
		$(".asks").each(function(){
			$(this).on("change",function(){
				var ask    = $(this).val();
				var cartid = $(this).attr("cartid");
				askedit(ask,cartid);
			});
		});
		
		$('.zz').on('click',function(){
			$(".cnote-bubble").hide();
		});
		
		/*
		$(".nameinput").on('click',function(){
			$(this).parents("p").siblings(".cnote-bubble").show();
			return false;
		});*/
		//隔行换色
		$('.confirm1 table tr:odd').addClass('odd');
		$('.confirm1 table tr:even').addClass('even');
		
		//隔行换色
		$('.online ul li:odd').addClass('odd');
		$('.online ul li:even').addClass('even');
		
		//删除购物车中的一件商品
		$('.remove').live('click',function(){
			
			$(this).parent('td').parent('tr').remove();	
			var id = $(this).attr("rel");
			delone(id);
			changetotal();
		});
		
		//减少商品数量
		$('.minus').live("click",function(){
			var obj    = $(this).siblings('li.num');
			var price  = parseInt($(this).attr("price"));
			var num    = parseInt(obj.html());
			var id     = $(this).attr("data-id");
			if(num==1){
				return false;
			}else{
				num -= 1;
				obj.html(num);
				price = price*num ;
				price = price.toFixed(2);
				$("#xjprice"+id).html(price);	
				setnum(id,price,num);			
				changetotal();
			}
		});
		//增加商品价格
		$('.plus').live("click",function(){
			var obj     = $(this).siblings('li.num');
			var price  = parseInt($(this).attr("price"));
			var num    = parseInt(obj.html());
			var id     = $(this).attr("data-id");
			if(num>=20){
				return false;
			}else{
				num += 1;
				obj.html(num);
				price = price*num ;
				price = price.toFixed(2);
				$("#xjprice"+id).html(price);
				setnum(id,price,num);
				changetotal();
			}
		});
		
		$('.addtable tr td input').click(function(){
			if($(this).filter(':checked')){
				$('.addtable tr').css({background:'',color:'#333'})
				$(this).parent('td').parent('tr').css({background:'#FE6736',color:'#fff'});	
				if($(this).val() == -1){
					$('.confirm .confirm1 .c1table').show();
					$(".addressForm").addClass("formTable");
				}else{
					$('.confirm .confirm1 .c1table').hide();
					$(".addressForm").removeClass("formTable");
				}
			}	
		})
	});
function askedit(ask,cartid){
	$.get("{:U('Order/editask')}",{cartid:cartid,ask:ask});
}
//计算价格
function changetotal(){
	
	var total      = 0;   //商品总价含运送费	
	var foodfee    = 0;   //商品总价格不含运送费
	var dliveryfee = "{$dliveryfee}" ? "{$dliveryfee}" : 0.00;  //运送费
	var outletid   = "{$outlet.id}";
	$.get("{:U('Dishes/calculateTotal')}",{outletid:outletid},function(d){
		
		if(d.status==1){
			foodfee = parseInt(d.data);
			total   = foodfee + parseInt(dliveryfee);
			total   = total.toFixed(2);
			foodfee = foodfee.toFixed(2);
			
			if(foodfee>=50){
				$('#freeDrink').show();
			}else{
				$('#freeDrink').hide();
			}

			$(".foodfee").val(foodfee)
			$(".totalprice").html(total);
		}
	});
}
//异步删除购物车中的商品
function delone(id){
	$.get("{:U('Dishes/delone')}",{id:id},function(html){
		$('.spc_ul').html(html);
		changetotal(); //计算总价
	});
}
//修改购物车中菜品的数量
function setnum(id,price,num){
	var postData    = {};
	postData.id     = id;
	postData.num    = num;
	postData.price  = price;
	$.post("{:U('Dishes/setnum')}",postData);
}

function getDliveryfee(lng,lat){
	var c_lng    = "{$outlet.longitude}";
	var c_lat    = "{$outlet.latitude}";
	var outletid = $('#outid').val();
	
	$.get("{:U('Order/getDliveryfee')}",{c_lng:c_lng,c_lat:c_lat,y_lng:lng,y_lat:lat,outletid:outletid},function(data){
		if(data.status){
			
			var totalprice = parseInt($('.totalprice').html());
			var servicefee = parseInt($('#dliveryfee').html());   
			
			dliveryfee = parseInt(data.dliveryfee);
			totalprice = parseInt(totalprice+dliveryfee-servicefee);
			
			dliveryfee = dliveryfee.toFixed(2);
			totalprice = totalprice.toFixed(2);
			
			$('#dliveryfee').html(dliveryfee);
			$('#shipfee').val(dliveryfee);
			$('.totalprice').html(totalprice);
		}else{
			alert(data.info);
		}
	},'json');
}
</script>
</body>
</html>
